package com.c.controller;

import com.c.entity.CheckItem;
import com.c.entity.PayLog;
import com.c.service.PayLogService;
import com.c.utils.MessageConstant;
import com.c.utils.PageResult;
import com.c.utils.QueryPageBean;
import com.c.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangxiangli
 * @create 2023-04-08-23:01
 */
@RequestMapping("/payLog")
@RestController
public class PayLogController {
    @Autowired
    private PayLogService payLogService;

    /**
     * 支付记录分页查询
     *
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = payLogService.pageQuery2(queryPageBean);
        return pageResult;
    }



    @GetMapping("/findByid")
    public Result findByid(Integer id){
        try {
            PayLog data = payLogService.getById(id);
            return new Result(true, MessageConstant.QUERY_COMMONSUCCESS, data);
        } catch (Exception e) {
            e.printStackTrace();
            //服务调用失败
            return new Result(false, MessageConstant.QUERY_COMMONFAILE);
        }
    }


    /**
     * 编辑
     *
     */
    @RequestMapping("/edit")
    public Result edit(@RequestBody PayLog payLog) {
        try {
            payLogService.updateById(payLog);
            return new Result(true, MessageConstant.COMMON_EDIT_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.COMMON_EDIT_FAILE);
        }
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(Integer id) {

        try {
            payLogService.removeById(id);
            return new Result(true, MessageConstant.COMMON_DELETE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.COMMON_DELETE_FAILE);
        }
    }
}
